﻿using System.Windows;
using System.Windows.Input;

namespace T68Control.View
{
    /// <summary>
    /// MyMessageBox.xaml 的交互逻辑
    /// </summary>
    public partial class MyMessageBox : Window
    {
        public MyMessageBox()
        {
            InitializeComponent();
        }

        public new string Title
        {
            get { return this.tbTitle.Text; }
            set { this.tbTitle.Text = value; }
        }

        public string Msg
        {
            get { return this.tbMsg.Text; }
            set { this.tbMsg.Text = value; }
        }

        private void btnYes_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void btnNo_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        public static bool? Show(string title, string msg, Window owner = null)
        {
            var msgBox = new MyMessageBox();
            msgBox.Title = title;
            msgBox.Msg = msg;
            msgBox.Owner = owner;
            return msgBox.ShowDialog();
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                this.DragMove();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            // 检查是否按下了回车键
            if (e.Key == Key.Enter)
            {
                // 回车键被按下，模拟按钮点击
                btnYes_Click(btnYes, new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent));
                e.Handled = true; // 标记按键已被处理
            }
            else if (e.Key == Key.N)
            {
                btnNo_Click(btnNo, new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent));
                e.Handled = true; // 标记按键已被处理
            }
        }
    }
}